/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs.database;

import sw6.digipecs.exceptions.NotSupportedException;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteQuery;

public class Factory<T> implements CursorFactory {

	private Class<T> mClass;

	public Factory(Class<T> c) {
		mClass = c;
	}

	@Override
	public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery,
			String editTable, SQLiteQuery query) {
		// TODO Find a better way than this if else...
		if (mClass == PictureCursor.class) {
			return (Cursor) new PictureCursor(db, masterQuery, editTable, query);
		} else if (mClass == PictureActiveCursor.class) {
			return new PictureActiveCursor(db, masterQuery, editTable, query);
		} else if (mClass == PictureIDCursor.class) {
			return new PictureIDCursor(db, masterQuery, editTable, query);
		} else if (mClass == PictureSituationIDCursor.class) {
			return new PictureSituationIDCursor(db, masterQuery, editTable, query);
		} else if (mClass == SentenceBoardStateCursor.class) {
			return new SentenceBoardStateCursor(db, masterQuery, editTable, query);
		} else if (mClass == SituationCursor.class) {
			return new SituationCursor(db, masterQuery, editTable, query);
		} else {
			throw new NotSupportedException("Factory cannot produce cursor from type");
		}
	}

}
